<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Jobs\DcsDataJob;
use Log;

/**
 * 从电厂获取DCS数据并保存到本地
 */
class DcsDataCmd extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'collect:dcsData {--datetime=default}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'collect dcsData';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $optionDate = $this->option('datetime');
        if($optionDate != 'default'){
            $datetime = $optionDate;
        }
        else{
            $datetime = date('Y-m-d H:i', time() - 10 * 60) . ':00';  ////取十分钟之前的数据
        }

        $params = array(
            'datetime' => $datetime,
            'factory_conn' => "mongodb",
            'local_conn' => "sqlsrv—local",
            'factory_data_table' => "history",
            'local_data_table' => "dcs_yongqiang2"
        );

        dispatch(new DcsDataJob($params));
        return 0;
    }
}
